package com.compass.mobile.presenters

import UserInfoManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.leanback.widget.Presenter
import com.compass.mobile.R
import com.compass.mobile.framework.ext.gone
import com.compass.mobile.framework.ext.visible
import com.compass.mobile.framework.utils.BigDecimalUtils
import com.compass.mobile.framework.utils.DateUtils
import com.compass.mobile.models.OrderBean
import dp2px
import setUrlRound

/**
 * Description：
 * Date:2024/6/19 10:04
 */
class OrderPresenter : Presenter() {

    override fun onCreateViewHolder(viewGroup: ViewGroup): ViewHolder {
        val view = LayoutInflater.from(viewGroup.context)
            .inflate(R.layout.item_order, viewGroup, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(viewHolder: Presenter.ViewHolder, item: Any) {
        if (item is OrderBean) {
            val vh = viewHolder as ViewHolder
            vh.tvType.text = UserInfoManager.getOrderConsultationTypeString(item.type)
            vh.tvStatus.text = UserInfoManager.getOrderTypeString(item.status)
            vh.tvDoctorName.text = item.doctorName
            vh.tvPositionName.text = item.positionName
            vh.tvDepartmentName.text = item.departmentName
            vh.tvCreateTime.text =
                "创建时间：${DateUtils.conversionTime(item.createTime, DateUtils.FORMAT_TWO)}"
            vh.tvPrice.text = "问诊金额：${BigDecimalUtils.divide(item.payPrice)}元"
            vh.imgHead.setUrlRound(item.doctorAvatar, dp2px(5f))

            if (item.status=="0") vh.tvGoToPay.visible() else vh.tvGoToPay.gone()

            if (item.status=="0"||item.status=="1") vh.tvCancelInquire.visible() else vh.tvCancelInquire.gone()

            if (item.status=="2"||item.status=="1") vh.tvGoToInquire.visible() else vh.tvGoToInquire.gone()

            if (item.status=="3"||item.status=="4"&& item.type=="1"){
                vh.tvGoToInquire.visible()
                vh.tvGoToInquire.text="查看记录"
            }else{
                vh.tvGoToInquire.gone()
            }

            if (item.status=="4"||item.status=="-1"||item.status=="-2") vh.tvAgainInquire.visible() else vh.tvAgainInquire.gone()

            if (item.status=="3") vh.tvToEvaluate.visible() else vh.tvToEvaluate.gone()



        }
    }

    override fun onUnbindViewHolder(viewHolder: Presenter.ViewHolder) {

    }


    class ViewHolder(view: View) : Presenter.ViewHolder(view) {
        var tvType: TextView
        var tvPositionName: TextView
        var tvDepartmentName: TextView
        var tvPrice: TextView
        var tvDoctorName: TextView
        var tvStatus: TextView
        var tvCreateTime: TextView
        var imgHead: ImageView
        var tvToEvaluate: TextView
        var tvAgainInquire: TextView
        var tvCancelInquire: TextView
        var tvGoToInquire: TextView
        var tvGoToPay: TextView


        init {
            tvGoToInquire = view.findViewById(R.id.tvGoToInquire)
            tvGoToPay = view.findViewById(R.id.tvGoToPay)
            tvToEvaluate = view.findViewById(R.id.tvToEvaluate)
            tvCancelInquire = view.findViewById(R.id.tvCancelInquire)
            tvAgainInquire = view.findViewById(R.id.tvAgainInquire)
            tvType = view.findViewById(R.id.tvType)
            tvStatus = view.findViewById(R.id.tvStatus)
            tvPrice = view.findViewById(R.id.tvPrice)
            tvCreateTime = view.findViewById(R.id.tvCreateTime)
            tvDoctorName = view.findViewById(R.id.tvDoctorName)
            tvPositionName = view.findViewById(R.id.tvPositionName)
            tvDepartmentName = view.findViewById(R.id.tvDepartmentName)
            imgHead = view.findViewById(R.id.imgHead)


        }
    }
}